package com.evan.webadmin.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.evan.webadmin.biz.model.SubjectOption;
import com.evan.webadmin.biz.dao.SubjectOptionMapper;
import com.evan.webadmin.biz.service.ISubjectOptionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Pavel
 * @since 2024-06-09
 */
@Service
public class SubjectOptionServiceImpl extends ServiceImpl<SubjectOptionMapper, SubjectOption> implements ISubjectOptionService {

    @Autowired
    private SubjectOptionMapper subjectOptionMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void deleteBySubjectId(Long subjectId) {
        subjectOptionMapper.deleteBySubjectId(subjectId);
    }

    @Override
    public List<SubjectOption> findBySubjectId(Long subjectId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("subject_id", subjectId);
        return subjectOptionMapper.selectList(queryWrapper);
    }
}
